<template>
  <el-container>
    <el-header  >
      <el-row :gutter="20">
        <el-col class="hidden-sm-only hidden-md-only hidden-sm-only hidden-lg-only hidden-xl-only" :xs="{span:8}">
          <el-menu :default-active="'1-0-0'"  :unique-opened="true" :style="{'background-color':'#B3C0D1','heigth':'60px'}" mode="horizontal" >
            <el-submenu index="1"  :unique-opened="true">
              <template #title>菜单</template>
              <el-submenu :index="'1-'+index+''" v-for="(item,index) in items" :key="index">
                  <template slot="title">{{item.name}}</template>
                  <el-menu-item-group>
                    <el-menu-item  @click="openPage(it.path);" :index="'1-'+index+'-'+k" v-for="(it,k) in item.childNode" :key="k">{{it.name}}</el-menu-item>
                  </el-menu-item-group>
                </el-submenu>
            </el-submenu>
          </el-menu>
        </el-col>
        
        <el-col :xs="{span:16}" :sm="{span:6,push:18}" :lg="{span:4,push:20}">
           <el-image :src="user.image"  :lazy="true" :style="{'heigth':'50px',width:'50px',margin:'5px 5px','vertical-align':'middle'}"></el-image>
          <el-button type="primary" size="default" @click="quit()">注销</el-button>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="200px" class="hidden-xs-only">
          <el-menu :default-openeds="defaultOpen">
            <el-submenu :index="index+''" v-for="(item,index) in items" :key="index">
              <template slot="title"><i class="el-icon-message"></i>{{item.name}}</template>
              <el-menu-item-group>
                <el-menu-item @click="openPage(it.path);" :index="index+'-'+k" v-for="(it,k) in item.childNode" :key="k">{{it.name}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
      </el-aside>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import http from "@/utils/request";
import router from "@/router/index";
import {Menus,Menu} from "@/domain/Menus";
import UserInfo from "@/domain/UserInfo";
import { AxiosResponse } from 'axios';


@Component({
  components: {
    // HelloWorld,
  },
})
export default class Home extends Vue {
  
  defaultOpen:Array<string>=[];
  items:Menus=[];
  user:UserInfo={admin:null,image:null,name:null,items:[] };

  created(){
    // http({
    //   url:'/user/info',
    //   method:'get'
    // }).then((resp:AxiosResponse<any>):void=>{
    //   this.user=resp.data;
    //   this.items=this.user.items as Menus;
    // });
  }

  openPage(path:string){
    router.push(path).catch((rea:any):any=>{});
  }

  quit(){
    localStorage.removeItem('token');
    router.push('/login').catch((rea:any):any=>{});  
  }
}
</script>

<style>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
    
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 160px;
  }
  
  body > .el-container {
    margin-bottom: 40px;
    height: 100%;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
</style>